<pro-header [title]="'测试-查询表格'"></pro-header>
<nz-card [nzBordered]="false">
    <form nz-form (ngSubmit)="getData()" [nzLayout]="'inline'">
        <div nz-row [nzGutter]="24">
            <div nz-col [nzSpan]="8" class="mb-md">
                <div nz-form-item class="d-flex">
                    <div nz-form-label><label for="no">规则编号</label></div>
                    <div nz-form-control class="flex-1">
                        <nz-input [(ngModel)]="pageQuery.no" name="no" [nzSize]="'large'" [nzPlaceHolder]="'请输入'" nzId="no"></nz-input>
                    </div>
                </div>
            </div>
            <div nz-col [nzSpan]="8" class="mb-md">
                <div nz-form-item class="d-flex">
                    <div nz-form-label><label for="status">使用状态</label></div>
                    <div nz-form-control class="flex-1">
                        <nz-select [(ngModel)]="pageQuery.status" name="status" nzId="status" [nzPlaceHolder]="'请选择'" [nzShowSearch]="true" [nzSize]="'large'">
                            <nz-option *ngFor="let i of status; let idx = index" [nzLabel]="i.text" [nzValue]="idx"></nz-option>
                        </nz-select>
                    </div>
                </div>
            </div>
            <div *ngIf="expandForm" nz-col [nzSpan]="8" class="mb-md">
                <div nz-form-item class="d-flex">
                    <div nz-form-label><label for="callNo">调用次数</label></div>
                    <div nz-form-control class="flex-1">
                        <nz-input [nzSize]="'large'" nzId="callNo"></nz-input>
                    </div>
                </div>
            </div>
            <div *ngIf="expandForm" nz-col [nzSpan]="8" class="mb-md">
                <div nz-form-item class="d-flex">
                    <div nz-form-label><label for="updatedAt">更新日期</label></div>
                    <div nz-form-control class="flex-1">
                        <nz-datepicker [nzSize]="'large'" [nzPlaceHolder]="'请输入更新日期'" nzId="updatedAt" class="d-block"></nz-datepicker>
                    </div>
                </div>
            </div>
            <div nz-col [nzSpan]="expandForm ? 24 : 8" class="mb-md" [class.text-right]="expandForm">
                <button nz-button type="submit"  [nzType]="'primary'" [nzLoading]="loading" [nzSize]="'large'">查询</button>
                <button nz-button type="reset" (click)="getData()" [nzSize]="'large'" class="mx-sm">重置</button>
                <a (click)="expandForm=!expandForm">
                    {{expandForm ? '收起' : '展开'}}
                    <i class="anticon" [class.anticon-down]="!expandForm" [class.anticon-up]="expandForm"></i>
                </a>
            </div>
        </div>  
    </form>
    <div class="mb-md">
            <button nz-button (click)="add()" [nzType]="'primary'" [nzSize]="'large'">
                <i class="anticon anticon-plus"></i><span>新建</span>
            </button>
            <ng-container *ngIf="selectedRows.length > 0">
                <button nz-button [nzSize]="'large'" class="ml-sm">批量操作</button>
                <nz-dropdown [nzPlacement]="'bottomLeft'">
                    <button nz-button nz-dropdown [nzSize]="'large'" class="ml-sm">
                        更多操作 <i class="anticon anticon-down"></i>
                    </button>
                    <ul nz-menu>
                        <li nz-menu-item (click)="remove()">删除</li>
                        <li nz-menu-item (click)="approval()">批量审批</li>
                    </ul>
                </nz-dropdown>
            </ng-container>
        </div>
    <div class="mb-md">
            <nz-alert [nzType]="'info'" [nzShowIcon]="true">
                <span alert-body>
                    已选择 <strong class="text-primary">{{selectedRows.length}}</strong> 项&nbsp;&nbsp;
                    服务调用总计 <strong>{{totalCallNo}}</strong> 万
                    <a *ngIf="totalCallNo > 0" (click)="clear()" class="ml-lg">清空</a>
                </span>
            </nz-alert>
        </div>
    <nz-table #nzTable [nzDataSource]="data" [nzPageSize]="pageQuery.pageSize" [nzLoading]='loading'
    (nzDataChange)="dataChange($event)" (nzPageIndexChange)="pageChange($event)" >
        <thead nz-thead>
          <tr>
            <th nz-th [nzCheckbox]='true'>
                    <label nz-checkbox [(ngModel)]="allChecked" 
                    [nzIndeterminate]="indeterminate"
                    (ngModelChange)="checkAll($event)"></label>
            </th>
            <th nz-th><span>规则编号</span></th>
            <th nz-th><span>描述</span></th>
            <th nz-th>
                <span>服务调用次数</span>
                <nz-table-sort [(nzValue)]="sortMap.callNo" (nzValueChange)="sort('callNo',$event)"></nz-table-sort>
            </th>
            <th nz-th><span>状态</span>
                <nz-dropdown [nzTrigger]="'click'">
                        <i class="anticon anticon-filter" nz-dropdown></i>
                        <ul nz-menu>
                            <li nz-menu-item *ngFor="let i of status">
                                <label nz-checkbox [(ngModel)]="i.value"><span>{{i.text}}</span></label>
                            </li>
                        </ul>
                        <div nz-table-filter>
                            <span nz-table-filter-confirm (click)="getData()">确定</span>
                            <span nz-table-filter-clear (click)="reset(status)">重置</span>
                        </div>
                </nz-dropdown>
            </th>
            <th nz-th>
                <span>更新时间</span>
                <nz-table-sort [(nzValue)]="sortMap.updatedAt" (nzValueChange)="sort('updatedAt',$event)"></nz-table-sort>
            </th>
            <th nz-th><span>操作</span></th>
          </tr>
        </thead>
        <tbody nz-tbody>
          <tr nz-tbody-tr *ngFor="let i of nzTable.data">
                <td nz-td [nzCheckbox]="true">
                        <label nz-checkbox [nzDisabled]="i.disabled" [(ngModel)]="i.checked" (ngModelChange)="refreshStatus($event)">
                        </label>
                    </td>
              <td>{{i.no}}</td>
              <td>{{i.description}}</td>
              <td class="text-center">{{i.callNo}}</td>
              <td><nz-badge [nzStatus]="i.statusType" [nzText]="i.statusText + '    ' + i.KKK"></nz-badge></td>
 
              <td>{{i.updatedAt | _date}}</td>
              <td nz-td>
                    <a (click)="setConfig(i.no)">配置</a>
                    <span nz-table-divider></span>
                    <a (click)="setModify(modalModifyContent)">修改</a>
                    <span nz-table-divider></span>
                    <a (click)="setUpdate(modalUpdateTitle, modalUpdateContent, modalUpdateFooter)">更新</a>
                    <span nz-table-divider></span>
                    <a (click)="msg.success('订阅警报' + i.no)">订阅警报</a>
                </td>
          </tr>
        </tbody>
      </nz-table>
</nz-card>
<nz-modal [nzVisible]="modalVisible" [nzTitle]="'新建规则'" [nzClosable]="true" [nzConfirmLoading]="loading"
    [nzContent]="modalContent" (nzOnOk)="save()" (nzOnCancel)="modalVisible=false">
    <ng-template #modalContent>
            <div nz-form-item class="d-flex">
                <div nz-form-label><label for="description">描述</label></div>
                <div nz-form-control class="flex-1">
                    <nz-input [(ngModel)]="description" name="description" [nzSize]="'large'" [nzPlaceHolder]="'请输入新规则描述'" ></nz-input>
                </div>
            </div>
    </ng-template>
</nz-modal>
<ng-template #modalModifyContent>
    <div nz-form-item class="d-flex">
        <div nz-form-label><label for="description">描述</label></div>
        <div nz-form-control class="flex-1">
            <nz-input [(ngModel)]="description" name="description" [nzSize]="'large'" [nzPlaceHolder]="'请输入新规则描述'" ></nz-input>
        </div>
    </div>
</ng-template>
<ng-template #modalUpdateTitle>
    <span>更新弹出层</span>
</ng-template>
<ng-template #modalUpdateContent>
    <div nz-form-item class="d-flex">
        <div nz-form-label><label for="description">描述</label></div>
        <div nz-form-control class="flex-1">
            <nz-input [(ngModel)]="description" name="description" [nzSize]="'large'" [nzPlaceHolder]="'请输入新规则描述'" ></nz-input>
        </div>
    </div>
</ng-template>
<ng-template #modalUpdateFooter>
    <div class="modal-footer">
        <button nz-button type="button" (click)='closeUpdateModal()' >关闭</button>
        <button nz-button type="submit" (click)='saveUpdateModel()' [nzLoading]="isConfirmLoading" [nzType]="'primary'">保存</button>
    </div>
  </ng-template>